import common from "../common";
import constants from "../constants";

const baseRelatedPartyApi = {
    transferClientZTreeData(datas) {
        let list = [];
        datas.forEach(item => {
            let obj = {};
            obj.id = item.sid;
            obj.pId = item.parent_sid;
            obj.label = item.name;
            obj.type = 'clientType';
            obj.children = [];
            if (item.children && item.children.length > 0) {
                let list2 = item.children.filter(item2 => {
                    return (item2.children && item2.children.length > 0) || (item2.clientList && item2.clientList.length > 0);
                })
                obj.children = obj.children.concat(baseRelatedPartyApi.transferClientZTreeData(list2));
            }
            if (item.clientList && item.clientList.length > 0) {
                item.clientList.forEach(item => {
                    let obj2 = {
                        id: item.sid,
                        // label: item.name,
                        label: item.code + ' | ' + item.name,
                        type: 'client',
                    }
                    obj.children.push(obj2);
                })
            }
            list.push(obj);
        });
        return list;
    },
    findBaseRelatedPartyTypeTree: (data, success, error) => {
        return common.requestData(constants.API_FindBaseRelatedPartyTypeTree, data, success, error);
    },
    findBaseRelatedPartyTypeTreeWithChildren: (data, success, error) => {
        return common.requestData(constants.API_FindBaseRelatedPartyTypeTreeWithChildren, data, success, error);
    },
    saveBaseRelatedPartyType: (data, success, error) => {
        return common.requestData(constants.API_SaveBaseRelatedPartyType, data, success, error);
    },
    deleteBaseRelatedPartyType: (data, success, error) => {
        return common.requestData(constants.API_DeleteBaseRelatedPartyType, data, success, error);
    },
    findBaseRelatedPartys: (data, success, error) => {
        return common.requestData(constants.API_FindBaseRelatedPartys, data, success, error);
    },
    getSysClentById: (data, success, error) => {
        return common.requestData(constants.API_GetSysClentById, data, success, error);
    },
    saveBaseRelatedParty: (data, success, error) => {
        return common.requestData(constants.API_SaveBaseRelatedParty, data, success, error);
    },
    batchDeleteBaseRelatedParty: (data, success, error) => {
        return common.requestData(constants.API_DeleteBaseRelatedPartys, data, success, error);
    },
    findSysUserClients: (data, success, error) => {
        return common.requestData(constants.API_FindSysUserClients, data, success, error);
    },
    settingClientSysUser: (data, success, error) => {
        return common.requestData(constants.API_SettingClientSysUser, data, success, error);
    },

    findBaseRelatedPartyBizOffices: (data, success, error) => {
        return common.requestData(constants.API_FindBaseRelatedPartyBizOffices, data, success, error);
    },
    saveBaseRelatedPartyBizOffice: (data, success, error) => {
        return common.requestData(constants.API_SaveBaseRelatedPartyBizOffice, data, success, error);
    },
    deleteBaseRelatedPartyBizOffice: (data, success, error) => {
        return common.requestData(constants.API_DeleteBaseRelatedPartyBizOffice, data, success, error);
    },

    findSysContractPersons: (data, success, error) => {
        return common.requestData(constants.API_FindSysContractPersons, data, success, error);
    },
    saveSysContractPerson: (data, success, error) => {
        return common.requestData(constants.API_SaveSysContractPerson, data, success, error);
    },
    deleteSysContractPerson: (data, success, error) => {
        return common.requestData(constants.API_DeleteSysContractPerson, data, success, error);
    },
    findUnBindSysUser: (data, success, error) => {
        return common.requestData(constants.API_FindUnBindSysUser, data, success, error);
    },
    importBaseRelatedParty: (data, success, error) => {
        return common.requestData(constants.API_ImportBaseRelatedParty, data, success, error);
    },
};

export default baseRelatedPartyApi;
